#include "mainwindow.h"

#include <QApplication>
#include <iostream>
#include <memory>
#include <string>

#include "unary.h"
#include "helper.h"

#include "routeguide.h"
#include "grpcserver.h"
#include "grpceventserverservice.h"
#include "grpceventdispatchercore.h"
void RunAllService()
{
    std::string db = routeguide::GetDbFileContent(0, nullptr);
    std::string server_address("0.0.0.0:50051");
    //RouteGuideImpl service(db);
    RouteGuideAsyncImpl service(db);
    ServerBuilder builder;
    builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());

    builder.RegisterService(&service);

    std::unique_ptr<Server> server(builder.BuildAndStart());
    std::cout << "Server listening on " << server_address << std::endl;
    server->Wait();
}


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

//    return a.exec();

    //RunServer();


    //RunAllService();

    g_pEventDispatcher.reset(new GrpcEventDispatcherCore);
    g_pGrpcServer.reset(GrpcServer::instance());
    g_pEventService = std::make_shared<GrpcEventServerService>();
    g_pGrpcServer->RegisterService(g_pEventService);
    g_pGrpcServer->StartGrpcServer("localhost", 6001);


        MainWindow w;
        w.show();

    return a.exec();

}
